<template>
  <view :style="themeColor">
    <view class="page">
      <fu-custom bgColor="bg-white" :isBack="true" :isBottom="true">
        <block slot="content">申请开票</block>
      </fu-custom>

      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout ApplyOpenInvoicessss_flex_1">
        <view class='flex flex-direction align-stretch ApplyOpenInvoicessss_fd1_0'>
          <view class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'>
            <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'>发票类型</text>
            <text class='ApplyOpenInvoicessss_fd1_0_c0_c1'>电子发票</text>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c1'>
            <text class='ApplyOpenInvoicessss_fd1_0_c1_c0'>发票信息</text>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c2'>
            <text class='ApplyOpenInvoicessss_fd1_0_c2_c0'>抬头类型</text>
            <benben-select-diy ref="showSelectPopup1689756647721" class-name='flex align-center flex' :items.sync="type"
              v-model="dataMessage.type" :label.sync="type_la" default-type="value" default-label="name"
              :allow-cancel='false' type="radio" :disabled='false'>
              <template v-for='(item,key0) in type'>
                <view v-if="item.isSelected" class='flex align-center flex ApplyOpenInvoicessss_fd1_0_c2_c1_c0'
                  :key="key0" @tap="$refs.showSelectPopup1689756647721.tapHandle(key0)">
                  <image class='ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0' mode="aspectFit" :src='STATIC_URL+"3.png"'>
                  </image>
                  <text class='ApplyOpenInvoicessss_fd1_0_c0_c1'>{{item.name}}</text>
                </view>
                <view v-else class='flex align-center flex ApplyOpenInvoicessss_fd1_0_c2_c1_c0' :key="key0"
                  @tap="$refs.showSelectPopup1689756647721.tapHandle(key0)">
                  <image class='ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0' mode="aspectFit" :src='STATIC_URL+"135.png"'>
                  </image>
                  <text class='ApplyOpenInvoicessss_fd1_0_c0_c1'>{{item.name}}</text>
                </view>
              </template></benben-select-diy>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'>
            <image class='ApplyOpenInvoicessss_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='ApplyOpenInvoicessss_fd1_0_c3_c1'>发票抬头</text>
            <input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2' type="text" :placeholder="`发票抬头不能为空`"
              confirm-type="done" :maxlength="24" placeholder-style="color:#BFBFBF;font-size:32rpx"
              v-model="dataMessage.username" />
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3' v-if="dataMessage.type=='2'">
            <image class='ApplyOpenInvoicessss_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='ApplyOpenInvoicessss_fd1_0_c3_c1'>公司税号</text>
            <input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2' type="text" :placeholder="`企业单位税号不能为空`"
              confirm-type="done" :maxlength="32" placeholder-style="color:#BFBFBF;font-size:32rpx"
              v-model="dataMessage.tax_number" />
          </view>
          <view class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'>
            <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'>设置为默认抬头</text>
            <benben-flex-switch-new class-name='flex flex' v-model="is_tk" :disabled='false'>
              <template v-slot:checked>

                <view class='flex flex position-relative align-center'>
                  <image class='ApplyOpenInvoicessss_checkfd1_0_c5_c1_c0_c0' mode="aspectFit" :src='STATIC_URL+"3.png"'>
                  </image>
                </view>

              </template>
              <template v-slot:unchecked>

                <view class='flex flex position-relative justify-end align-center'>
                  <image class='ApplyOpenInvoicessss_noCheckfd1_0_c5_c1_c1_c0' mode="aspectFit"
                    :src='STATIC_URL+"213.png"'></image>
                </view>

              </template>
            </benben-flex-switch-new>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c6'>
          </view>
          <view class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'>
            <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'>发票内容</text>
            <text class='ApplyOpenInvoicessss_fd1_0_c0_c1'>商品明细</text>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c6'>
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'>
            <image class='ApplyOpenInvoicessss_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='ApplyOpenInvoicessss_fd1_0_c3_c1'>联系方式</text>
            <input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2' type="number" :placeholder="`联系方式不能为空`"
              confirm-type="done" :maxlength="11" placeholder-style="color:#BFBFBF;font-size:32rpx"
              v-model="dataMessage.mobile" />
          </view>
          <view class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'>
            <image class='ApplyOpenInvoicessss_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"282.png"'></image>
            <text class='ApplyOpenInvoicessss_fd1_0_c3_c1'>电子邮箱</text>
            <input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2' type="text" :placeholder="`电子邮箱不能为空`"
              confirm-type="done" :maxlength="32" placeholder-style="color:#BFBFBF;font-size:32rpx"
              v-model="dataMessage.email" />
          </view>
        </view>
        <view class='flex flex-wrap align-center justify-center ApplyOpenInvoicessss_fd1_1'>
          <button class='ApplyOpenInvoicessss_fd1_1_c0' @tap.stop="editAddFunc()">提交</button>
        </view>
      </view>




    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "type": [{
          "name": "个人",
          "value": "1",
          "image": ""
        }, {
          "name": "企业",
          "value": "2",
          "image": ""
        }],
        "is_tk": false,
        "dataDetails": {
          "invite_code": "",
          "address": "",
          "address_code": "",
          "hobby": "",
          "tags": "",
          "id": "",
          "userlevel_id": "",
          "mobile": "",
          "real_name": "",
          "avatar": "",
          "account": "",
          "email": "",
          "birthday": "",
          "gender": "",
          "create_time": "",
          "user_money": "",
          "freeze_money": "",
          "total_consumption_money": "",
          "score": "",
          "_mobile": "",
          "coupon": "",
          "collection_count": "",
          "browse_count": "",
          "total_money": "",
          "certified": "",
          "nickname": "",
          "is_pay_password": "",
          "follow_count": ""
        },
        "type_la": "",
        "dataMessage": {
          "user_nickname": "",
          "username": "",
          "tax_number": "",
          "mobile": "",
          "email": "",
          "type": "",
          "is_default": "",
          "status": "",
          "create_time": "",
          "type_name": ""
        },
        "id": ""
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        id
      } = options
      if (id !== undefined) this.id = id
      this.getMessageFunc()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //获取单个发票信息
      async getMessageFunc() {
        this.dataMessage.type = '1';
        if (this.id != '') {
          //请求方法
          //数据验证

          let datadataMessage = await this.$api.get(global.apiUrls.post6442399c6fca9, {
            aid: this.id
          });

          if (datadataMessage.data.code != 1) {
            this.$message.info(datadataMessage.data.msg);
            return
          }
          let infodataMessage = datadataMessage.data;
          this.dataMessage = infodataMessage.data

          if (this.dataMessage.is_default == '1') {
            this.is_tk = true;
          } else {
            this.is_tk = false;
          }
        }
      },
      //添加或编辑
      async editAddFunc() {
        if (!this.dataMessage.username) {
          this.$message.info('请输入发票抬头');
          return;
        }
        if (!this.dataMessage.mobile) {
          this.$message.info('请输入联系方式');
          return;
        }
        if (!validate(this.dataMessage.mobile, 'phone')) {
          this.$message.info('请输入正确的联系方式');
          return false;
        }
        if (!this.dataMessage.email) {
          this.$message.info('请输入电子邮箱');
          return;
        }
        if (!validate(this.dataMessage.email, 'email')) {
          this.$message.info('请输入正确的邮箱');
          return false;
        }
        if (this.dataMessage.type == 2) {
          if (!this.dataMessage.tax_number) return this.$message.info('请输入公司税号');
        }
        this.dataMessage.is_default = this.is_tk ? 1 : 0;
        this.dataMessage.aid = this.id;
        uni.setStorageSync('invoice', this.dataMessage);
        this.$urouter.navigateTo(`/pages/fp/invoiceConfirm/invoiceConfirm?aid=${this.id}`);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .ApplyOpenInvoicessss_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .ApplyOpenInvoicessss_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
  }

  .ApplyOpenInvoicessss_fd0_0_c0_c0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
  }

  .ApplyOpenInvoicessss_fd0_0_c0 {
    width: 180rpx;
  }

  .ApplyOpenInvoicessss_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
  }

  .ApplyOpenInvoicessss_flex_1 {
    margin: 0rpx 0rpx 32rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_1_c0 {
    background: var(--benbenbgColor7);
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor3);
    width: 686rpx;
    height: 88rpx;
    line-height: 88rpx;
    font-weight: 400;
  }

  .ApplyOpenInvoicessss_fd1_1 {
    position: fixed;
    left: 0rpx;
    bottom: calc(40rpx + var(--window-bottom));
    width: 750rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c6 {
    background: rgba(248, 248, 248, 1);
    height: 20rpx;
    background-size: 100% auto !important;
  }

  .ApplyOpenInvoicessss_noCheckfd1_0_c5_c1_c1_c0 {
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    width: 36rpx;
    height: 36rpx;
  }

  .ApplyOpenInvoicessss_checkfd1_0_c5_c1_c0_c0 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c3_c2 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #333;
    text-align: right;
  }

  .ApplyOpenInvoicessss_fd1_0_c3_c1 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c3_c0 {
    width: 12rpx;
    height: 12rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 8rpx 0rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c3 {
    border-bottom: 1px solid #eee;
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 18rpx 18rpx 18rpx 18rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c2_c1_c0 {
    margin: 0rpx 0rpx 0rpx 48rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c2_c0 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx auto 0rpx 0rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c2 {
    border-bottom: 1px solid #eee;
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 20rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c1_c0 {
    color: var(--benbenFontColor5);
    font-size: 28rpx;
    font-weight: 700;
    line-height: 40rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c1 {
    background: rgba(0, 142, 77, 0.1);
    background-size: 100% auto !important;
    padding: 24rpx 52rpx 24rpx 52rpx;
  }

  .ApplyOpenInvoicessss_fd1_0_c0_c1 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 400;
    color: #333333;
  }

  .ApplyOpenInvoicessss_fd1_0_c0_c0 {
    line-height: 45rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
  }

  .ApplyOpenInvoicessss_fd1_0_c0 {
    margin: 0rpx 32rpx 0rpx 32rpx;
    padding: 32rpx 0rpx 32rpx 20rpx;
  }

  .ApplyOpenInvoicessss_fd1_0 {
    background: var(--benbenbgColor1);
    background-size: 100% auto !important;
    margin: 0rpx 0rpx 150rpx 0rpx;
  }
</style>